<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<link rel="stylesheet" type="text/css" href="css/style_5.css" />
</head>

<body>
	<header class="upload-hedaer">
		<a href="javaScript:history.back(-1)" class="upload-fh"></a>
		<div>上传</div>
		
	</header>
	<section class="upload-section">
		<!-- <article class="upload-article-text">
			<textarea oninput="autoTextarea(this)" placeholder="发布内容" class="upload-textarea"></textarea>
		</article> -->
		<form action="" enctype="multipart/form-data">
			<article class="upload-piclist">
				<div class="upload-file">
					<input type="file" name="photo" id="file" accept="image/*" />
				</div>
			</article>
			<button class="submit" type="submit">发布</button>
		</form>
	</section>
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
	<script src="js/jquery.cookie.min.js"></script>
	<!-- <script src="js/index.js"></script> -->
	<script>
		$('#file').change(function (e) {
			var he = this.files[0]
			var url = URL.createObjectURL(he)
			$('.upload-file').css('background-image', `url(${url})`)
		})
		$('form').submit(function (e) {
			e.preventDefault()
			if ($('#file').get(0).files[0]) {
				$.ajax({
					method: 'post',
					data: new FormData(this),
					url: '/upload',
					contentType: false,
					processData: false
				}).done(function (data) {
					alert(data)
					location.href = '/member'
				})
			} else {
				alert('你还没有上传图片')
			}

		})
	</script>
	<style>

	</style>
</body>

</html>